<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page contentType="text/html;charset=UTF-8" %>
<%@page import="java.util.*" %>
<%@page import="com.lmpop.frame.util.FileIO" %>
<%@page import="com.lmpop.frame.util.Config" %>
<%@page import="java.io.*,java.util.regex.Matcher,java.util.regex.Pattern" %>
	<%
	request.setCharacterEncoding("UTF-8");
	String cust_id="";
	if( session.getAttribute("session_cust_id") != null )
	{
		cust_id = session.getAttribute("session_cust_id").toString();
	}		
	String filelist = "",file_path="";
	if(request.getParameter("filelist")!=null && !request.getParameter("filelist").equals("")){
		filelist = request.getParameter("filelist");
	}	
	if(request.getParameter("file_path")!=null && !request.getParameter("file_path").equals("")){
		file_path = request.getParameter("file_path");
	}	
//out.print(filelist);
	
	Config configFile = new Config();
	configFile.init();
	String rootpath = configFile.getString("rootpath");
	String content = "" ,templateDir =rootpath+"templets/html/www/"+filelist;
	//templateDir =rootpath+"templets/html"+file_path+filelist;
	//out.println("路径--------------"+templateDir);
	FileIO fileio = new FileIO();		
	
//content = fileio.LoadFile(templateDir);
	
	
	///////////////////////////////////////////////////////////  
	/****************
	 * @author by Zhouxq 
	 * decide display picture or others
   ****************
   */
		
		Pattern p = Pattern.compile(".+\\.(jpg|gif|jpeg|png|bmp)$");
		Matcher m = p.matcher(filelist);
		
		if(m.matches()){
				content	="<img src='/templets/html/404_01.jpg' />";
			}else{
				content = fileio.LoadFile(templateDir);
		}
  
  
  ////////////////////////////////////////////////////////////
   String edit="",contents="";
   if(request.getParameter("edit") != null){
   	 edit = request.getParameter("edit");
   }
   
   if(request.getParameter("contents") != null){
   	 contents = request.getParameter("contents");
   }
   
   if(edit.equals("true")){
   		fileio.SaveToFile(contents,templateDir);
   		out.print("<script>alert('编辑模板成功！');window.location.href='edit.jsp?filelist="+filelist+"';</script>");
   }	
	%>
<html>		
  <head>
  <title>在线编辑模板</title>
	<link href="/program/admin/index/css/style.css" rel="stylesheet" type="text/css">
	<script type="text/javascript" src="/js/commen.js"></script>
	<script type="text/javascript" src="edit.js"></script>
</head>

<body>
	<table width="100%" cellpadding="0" cellspacing="0" border="0">
		<tr>
			<td width="90%">
				<h1>在线编辑模板</h1>
			</td>
		</tr>
	</table>
<form id="certForm" name="certForm" method="post" action="edit.jsp?edit=true&filelist=<%=filelist%>" target="_self" onSubmit="return check();">
	<table width="100%" cellpadding="1" cellspacing="0" border="0" class="listtab">
			
<tr>
		<td>
			<textarea rows="30" cols="120" name="contents" id="contents"><%=content%></textarea>
		
		</td>
	</tr>
</table>

<table width="100%" cellpadding="0" cellspacing="0" border="0">	
	<tr>
		<td align="center">	
			<input type="submit" name="tradeSub" value="提交信息" class="buttoncss"/>
			<input class="buttoncss" type="button" name="tradeRut" value="返回" onClick="javascript:window.location.href='index.jsp?file_path=<%=file_path%>'" />
		</td>
	</tr>
</table>
	</form>
</body>

</html>
